import Thunk from 'redux-thunk';
import {connect} from 'react-redux';
import {
  createReactNavigationReduxMiddleware,
  createReduxContainer,
} from 'react-navigation-redux-helpers';
import {createStore, applyMiddleware, compose} from 'redux';
import Reducers from '../reducers/index';
import AppNavigator from '../navigator/app-navigator';
// Note: createReactNavigationReduxMiddleware must be run before reduxifyNavigator
const NavigationMiddleware = createReactNavigationReduxMiddleware(
  state => state.nav,
  'root',
);

const App = createReduxContainer(AppNavigator, 'root');
const mapStateToProps = state => ({
  state: state.nav,
});
export const RootNavigator = connect(mapStateToProps)(App);

// const enhancer = compose(
//   applyMiddleware(Thunk, NavigationMiddleware, createLogger()),
// );
const enhancer = compose(applyMiddleware(Thunk, NavigationMiddleware));
export const RootStore = createStore(Reducers, enhancer);
